package mo.golden;

import java.util.ArrayList;
import java.util.List;

public class L01_08 {

    public void setZeroes(int[][] matrix) {
        List<int[]> zeros = new ArrayList<>();
        int m = matrix.length, n = matrix[0].length;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (matrix[i][j] == 0) {
                    zeros.add(new int[]{i, j});
                }
            }
        }

        for (int i = 0; i < zeros.size(); i++) {
            int[] coordinate = zeros.get(i);
            int x = coordinate[0];
            int y = coordinate[1];
            for (int j = 0; j < n; j++) {
               matrix[x][j] = 0;
            }
            for (int j = 0; j < m; j++) {
                matrix[j][y] = 0;
            }
        }
    }

}
